﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WP09S03_OfficeTracking.Controller;

namespace WP09S03_OfficeTracking
{
    public partial class DiagAddEmpoyee : WP09S03_OfficeTracking.ParentClass.ParentDiag
    {
        private bool bAddNew;
        private string origID;
        private string origNumber;
        private string origName;
        private string origEmail;
        
        public DiagAddEmpoyee()
        {
            InitializeComponent();
            bAddNew = true;
            this.lblSubTitle.Text = "Add New Employee Info";
        }

        public DiagAddEmpoyee(string id, string name, string number, string email)
        {
            InitializeComponent();

            bAddNew = false;
            this.lblSubTitle.Text = "Edit Employee Info";
            this.origID = id;
            this.origName = name;
            this.origNumber = number;
            this.origEmail = email;

            this.controlID.UserText = id;
            this.controlName.UserText = name;
            this.maskedTextBoxNumber.Text = number;
            this.controlEmail.UserText = email;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
       
            EmployeController controller = new EmployeController();
            try
            {

                if (bAddNew)
                {
                    controller.AddEmployee(controlID.UserText,
                                controlName.UserText,
                                maskedTextBoxNumber.Text,
                                controlEmail.UserText);
                }
                else
                {
                    controller.UpdateEmployee(controlID.UserText,
                                controlName.UserText,
                                maskedTextBoxNumber.Text,
                                controlEmail.UserText,
                                origID, origName, origNumber, origEmail);
                }
                this.DialogResult = DialogResult.OK;
             }
             catch (Exception exc)
             {
                 this.SetMessage(exc.Message);
             }
               
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
